﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Controllers
{
    public class InvestorController : BaseController
    {
        public ActionResult Find(int start, int limit)
        {
            string sql = @"SELECT a.Id,InvestorNO,a.Sex,a.Name,a.IDNO,a.Tel,a.EMail,a.Address,a.EduLevel,MaritalStatus
	,Occupation,Income,Character,c.Name Marketer,b.Name IM,StarLevel,CommissionRate,InvestMSG,RiskLevel
	,BankName,BankAccount,Brokerage,Remarks
  FROM CMS_Investor a,CMS_Intermediation b,Employee c
  where a.IMID=b.Id and a.MarketID=c.Id;";
            IEnumerable<InvestorDTO> list = ctx.ExecuteQuery<InvestorDTO>(sql).ToList();
            CJson CJson = new CJson();
            string json = CJson.ToJsonString("totalCount:" + list.Count() + ",data", list.Skip(start).Take(limit).ToList());
            return Content(json);
        }
        public ActionResult Delete(int id)
        {
            var rdto = new ResultMessages();
            rdto.Message = "";
            CMS_Investor model = ctx.CMS_Investor.Single(q => q.Id == id);
            try
            {
                ctx.CMS_Investor.DeleteOnSubmit(model);
                ctx.SubmitChanges();
                rdto.Message = "删除成功";
                rdto.Result = true;
            }
            catch (Exception ex)
            {
                rdto.Message = "删除失败";
                rdto.Result = false;
            }
            return Json(rdto);
        }
    }
}